#include <init/PIC.h>
#include <asmutils.h>

void pic_remap(_s32 offset1, _s32 offset2)
{
    _u8 a1, a2;

    a1 = inb(PIC1_DATA);                        // save masks
    a2 = inb(PIC2_DATA);

    outb(PIC1_COMMAND, ICW1_INIT+ICW1_ICW4);    // starts the initialization sequence
    io_wait();
    outb(PIC2_COMMAND, ICW1_INIT+ICW1_ICW4);
    io_wait();
    outb(PIC1_DATA, offset1);                   // define the PIC vectors
    io_wait();
    outb(PIC2_DATA, offset2);
    io_wait();
    outb(PIC1_DATA, 4);                         // continue initialization sequence
    io_wait();
    outb(PIC2_DATA, 2);
    io_wait();

    outb(PIC1_DATA, ICW4_8086);
    io_wait();
    outb(PIC2_DATA, ICW4_8086);
    io_wait();

    outb(PIC1_DATA, a1);   			// restore saved masks.
    outb(PIC2_DATA, a2);
}

void pic_sendEOI(_u8 irq_num, _u8 irq_start_pic2)
{
    if(irq_num >= irq_start_pic2)
	outb(PIC2_COMMAND, PIC_EOI);

    outb(PIC1_COMMAND, PIC_EOI);
}

